<template>
  <div @keyup.enter="getData()">
    <el-form class="query-form" @submit.prevent :inline="true" :model="params">
      <el-form-item>
        <el-input v-model="params.customer_name" placeholder="客户名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData"></c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      loading: false,
      params: {
        index: 1,
        size: 15,
        customer_name: '',
      },
      serviceName: 'insurance',
      tableName: 'no_ins_customer_view',
      tableData: [],
      totalCount: 0,
      tableColumns: [
        { attrs: { label: '客户名称', prop: 'customer_name', minWidth: 150 } },
        { attrs: { label: '联系人', prop: 'contact' } },
        { attrs: { label: '联系电话', prop: 'mobile_no' } },
        {
          attrs: { label: '规模(数量)', prop: 'scale' },
          process: (v, row) => (v ? `${v}${row.uscale || ''}` : '-'),
        },
        { attrs: { label: '申请贷款资金', prop: 'apply_funds' } },
        {
          attrs: { label: '放款时间', prop: 'load_date' },
          process: v => this.$utils.dateFormat(v, 'yyyy.MM.dd'),
        },
        {
          attrs: { label: '担保结束时间', prop: 'load_end_date' },
          process: v => this.$utils.dateFormat(v, 'yyyy.MM.dd'),
        },
      ],
    }
  },
  computed: {
    clientId() {
      return this.$store.getters.clientId
    },
  },
  watch: {},
  created() {
    // this.params['agency_id.eq'] = this.clientId
    this.getData()
  },
  mounted() {},
  methods: {
    async getData(index = 1) {
      this.params.index = index
      this.loading = true
      const [res] = await this.$utils.promise(
        this.$api.getData(this.serviceName, this.tableName, this.params, { load_date: 'asc' })
      )
      this.loading = false
      this.tableData = (res && res.data && res.data.data) || []
      this.totalCount = (res && res.data && res.data.totalCount) || 0
    },
  },
}
</script>
<style lang="scss" scoped></style>
